package com.lagou.plugin;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.omg.CORBA.Object;

import java.lang.reflect.Executable;
import java.sql.Connection;
import java.util.Properties;

/**
 * 自定义插件
 */
@Intercepts({
        @Signature(
                type = StatementHandler.class,
                method = "prepare",
                args = {Connection.class, Integer.class}
        )
})
public class MyPlugin implements Interceptor {

        /**
         * 拦截方法: 只要被拦截的目标对象的目标方法被执行,每次都会执行intercept方法
         */
        @Override
        public java.lang.Object intercept(Invocation invocation) throws Throwable {
                System.out.println("==========自定义插件=========");
                System.out.println("添加增强逻辑");
                return invocation.proceed();// 执行原方法
        }

        /**
         * 主要为了把当前的拦截器生成代理存在拦截器链中
         */
        @Override
        public java.lang.Object plugin(java.lang.Object target) {
                System.out.println("将要包装的目标对象" + target);
                return Plugin.wrap(target, this);
        }

        /**
         * 获取配置文件的参数
         */
        @Override
        public void setProperties(Properties properties) {
                System.out.println("插件配置的初始化参数" + properties);
        }
}
